package com.core.family.gen.service.gen.Impl;

import com.core.family.gen.config.GenConfManger;
import com.core.family.gen.cons.DSTypeEnum;
import com.core.family.gen.domain.po.TableBeanPo;
import com.core.family.gen.domain.po.TableColumnPo;
import com.core.family.gen.service.gen.IGenHandler;
import com.core.family.gen.service.gen.ITemplateGenService;
import com.core.family.gen.service.gen.Impl.mssql.GenMssqlHandler;
import com.core.family.gen.service.gen.Impl.mysql.GenMysqlHandler;
import com.core.family.gen.service.gen.Impl.oracel.GenOracleHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: corel
 * @description:
 * @author: honglei
 * @create: 2022-03-09 14:53
 */

@Service
public class GenHandlerProxy implements IGenHandler {

    private static Map<String, IGenHandler> map = new HashMap<>();

    {
        map.put(DSTypeEnum.mysql.name(), new GenMysqlHandler());
        map.put(DSTypeEnum.oracle.name(), new GenOracleHandler());
        map.put(DSTypeEnum.mssql.name(), new GenMssqlHandler());
    }


    @Autowired
    ITemplateGenService generaeService;

    private static IGenHandler codeGenHandler;

    @Override
    public void setConfig(GenConfManger config) {
        codeGenHandler = map.get(config.getDsType().getName());
        codeGenHandler.setConfig(config);
    }

    @Override
    public List<TableBeanPo> tablesList() throws Exception {
        return codeGenHandler.tablesList();
    }

    @Override
    public List<TableColumnPo> getColumns(String table) throws Exception {
        return codeGenHandler.getColumns(table);
    }

    @Override
    public boolean genCode(TableBeanPo columnBean) throws Exception {
        return codeGenHandler.genCode(columnBean);
    }
}
